//
//  YMCommentViewController.m
//  YMCommentDemo
//
//  Created by lantaiyuan on 2017/2/24.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "YMCommentViewController.h"
#import "YMCommentView.h"
#import "YMCommentContentView.h"
#import "YMCommentDriverView.h"
#import "YMCommentStationFacilityView.h"
#import "YMCommentEmergencyView.h"
#import "YMCommentStationActivityView.h"
#import "YMCommentWayStationView.h"

#define SYS_SIZE [UIScreen mainScreen].bounds.size

@interface YMCommentViewController ()<YMCommentContentViewDelegate>
@property (nonatomic, strong) YMCommentView * commentView;
@property (nonatomic, strong) YMCommentContentView * commentContenView;
@property (nonatomic, strong) YMCommentDriverView * driverView;
@property (nonatomic, strong) YMCommentStationFacilityView * stationFacilityView;
@property (nonatomic, strong) YMCommentEmergencyView * emergencyView;
@property (nonatomic, strong) YMCommentStationActivityView * stationActivityView;
@property (nonatomic, strong) YMCommentWayStationView * wayStaionView;

@property (nonatomic, strong) UIView * maskView;
@end

@implementation YMCommentViewController

#pragma mark - Lazy

- (UIView *)commentView{
    if (!_commentView) {
        _commentView = [[YMCommentView alloc] initWithFrame:CGRectMake(0, SYS_SIZE.height - 350, SYS_SIZE.width, 350)];
    }
    return _commentView;
}

- (UIView *)commentContenView{
    if (!_commentContenView) {
        _commentContenView = [[YMCommentContentView alloc] initWithFrame:CGRectMake(0, SYS_SIZE.height - 350, SYS_SIZE.width, 350)];
        _commentContenView.delegate = self;
    }
    return _commentContenView;
}

- (YMCommentDriverView *)driverView{
    if (!_driverView) {
        _driverView = [[YMCommentDriverView alloc] initWithFrame:CGRectMake(0, SYS_SIZE.height - 350, SYS_SIZE.width, 350)];
    }
    return _driverView;
}

- (YMCommentStationFacilityView *)stationFacilityView{
    if (!_stationFacilityView) {
        _stationFacilityView = [[YMCommentStationFacilityView alloc] initWithFrame:CGRectMake(0, SYS_SIZE.height - 350, SYS_SIZE.width, 350)];
    }
    return _stationFacilityView;
}

- (YMCommentEmergencyView *)emergencyView{
    if (!_emergencyView) {
        _emergencyView = [[YMCommentEmergencyView alloc] initWithFrame:CGRectMake(0, SYS_SIZE.height - 350, SYS_SIZE.width, 350)];
    }
    return _emergencyView;
}

- (YMCommentStationActivityView *)stationActivityView{
    if (!_stationActivityView) {
        _stationActivityView = [[YMCommentStationActivityView alloc] initWithFrame:CGRectMake(0, SYS_SIZE.height - 350, SYS_SIZE.width, 350)];
    }
    return _stationActivityView;
}

- (YMCommentWayStationView *)wayStaionView{
    if (!_wayStaionView) {
        _wayStaionView = [[YMCommentWayStationView alloc] initWithFrame:CGRectMake(0, SYS_SIZE.height - 350, SYS_SIZE.width, 350)];
    }
    return _wayStaionView;
}

- (UIView *)maskView{
    if (!_maskView) {
        _maskView = [[UIView alloc] initWithFrame:self.view.bounds];
        _maskView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
        
    }
    return _maskView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
        
    [self.view addSubview:self.maskView];
    [self.view addSubview:self.commentView];
    
    self.commentView.layer.shadowColor = [UIColor darkGrayColor].CGColor;
    self.commentView.layer.shadowOffset = CGSizeMake(0, 0);
    self.commentView.layer.shadowOpacity = 0.3;
    self.commentView.layer.shadowRadius = 0.7;
    
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSelfView)];
    [self.maskView addGestureRecognizer:tapGesture];
    
    
    __weak typeof(self) weakSelf = self;
    self.commentView.cancelBtnActionBlock = ^{
        if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(cancel)]) {
            [weakSelf.delegate cancel];
        }
    };
    
    self.driverView.backBlock = ^{
        [weakSelf.driverView removeFromSuperview];
    };
    
    self.stationFacilityView.backBlock = ^{
        [weakSelf.stationFacilityView removeFromSuperview];
    };
    
    self.emergencyView.backBlock = ^{
        [weakSelf.emergencyView removeFromSuperview];
    };
    
    self.stationActivityView.backBlock = ^{
        [weakSelf.stationActivityView removeFromSuperview];
    };
    
    self.wayStaionView.backBlock = ^{
        [weakSelf.wayStaionView removeFromSuperview];
    };
    
    // 站台
    self.commentView.selectStationCommentItemBlock = ^(StationCommentType type){
        switch (type) {
            case StationCommentTypeCrowd:
            {
                NSLog(@"StationCommentTypeCrowd");
                weakSelf.commentContenView.commentType = YMCommentContentViewTypeCrown;
                [weakSelf.view addSubview:weakSelf.commentContenView];
            }
                break;
            case StationCommentTypeFacility:
            {
                NSLog(@"StationCommentTypeFacility");
                [weakSelf.view addSubview:weakSelf.stationFacilityView];
            }
                break;
            case StationCommentTypeEmergency:
            {
                NSLog(@"StationCommentTypeEmergency");
                [weakSelf.view addSubview:weakSelf.emergencyView];
            }
                break;
            case StationCommentTypeClean:
            {
                NSLog(@"StationCommentTypeClean");
                weakSelf.commentContenView.commentType = YMCommentContentViewTypeClean;
                [weakSelf.view addSubview:weakSelf.commentContenView];
            }
                break;
            case StationCommentTypeActivity:
            {
                NSLog(@"StationCommentTypeActivity");
                [weakSelf.view addSubview:weakSelf.stationActivityView];
            }
                break;
                
            default:
                break;
        }
    };
    
    // 车辆
    self.commentView.selectVehicleCommentItemBlock = ^(VehicleCommentType type){
        switch (type) {
            case VehicleCommentTypeOverMiddleStation:
            {
                NSLog(@"VehicleCommentTypeOverMiddleStation");
                [weakSelf.view addSubview:weakSelf.wayStaionView];
            }
                break;
            case VehicleCommentTypeCrowd:
            {
                NSLog(@"VehicleCommentTypeCrowd");
                weakSelf.commentContenView.commentType = YMCommentContentViewTypeCrown;
                [weakSelf.view addSubview:weakSelf.commentContenView];
            }
                break;
            case VehicleCommentTypeEmergency:
            {
                NSLog(@"VehicleCommentTypeEmergency");
                [weakSelf.view addSubview:weakSelf.emergencyView];
            }
                break;
            case VehicleCommentTypeDriver:
            {
                NSLog(@"VehicleCommentTypeDriver");
                [weakSelf.view addSubview:weakSelf.driverView];
            }
                break;
            case VehicleCommentTypeClean:
            {
                NSLog(@"VehicleCommentTypeClean");
                weakSelf.commentContenView.commentType = YMCommentContentViewTypeClean;
                [weakSelf.view addSubview:weakSelf.commentContenView];
            }
                break;
            case VehicleCommentTypeTemperature:
            {
                NSLog(@"VehicleCommentTypeTemperature");
                
                weakSelf.commentContenView.commentType = YMCommentContentViewTypeTempreture;
                [weakSelf.view addSubview:weakSelf.commentContenView];
            }
                break;
                
            default:
                break;
        }
    };
}

- (void)tapSelfView{
    if (_touchTapBlock) {
        _touchTapBlock();
    }
}

#pragma mark - YMCommentContentViewDelegate
- (void)commentContentView:(YMCommentContentView *)commentContentView didClickBackBtn:(UIButton *)btn{
    NSLog(@"___________Delegate______");
    [self.commentContenView removeFromSuperview];
    self.commentContenView = nil;
}
@end
